package org.lg.studyspringboot20.dao;

import org.lg.studyspringboot20.entity.Admin;
import org.lg.studyspringboot20.entity.AdminExample;
import org.lg.studyspringboot20.mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

@Repository("adminDao")
public class AdminDaoImpl implements AdminDao,AdminForCatOwenerDao{
    @Autowired
    private AdminMapper adminMapper;

    public AdminMapper getAdminMapper() {
        return adminMapper;
    }

    public void setAdminMapper(AdminMapper adminMapper) {
        this.adminMapper = adminMapper;
    }

    public AdminDaoImpl() throws IllegalAccessException, SQLException, ClassNotFoundException {
        //connection = ReflectJDBC.init();
    }
    //查询所有，函数方法  返回值类型   方法名   和参数列表
    public List<Admin> getAllAdmin() throws Exception{
        return adminMapper.selectByExample(null);
    }
    public Integer add(Admin admin){
        AdminExample adminExample = new AdminExample();  //example 示例查询，给我一个例子 我按例子查询
        adminExample.createCriteria().andAdidEqualTo(admin.getAdid()); //createCriteria() 创建一个criteria接口的匿名实现类，添加一个where子句 and表达式 这次and的是adid=admin对象的adid
        return adminMapper.insertSelective(admin);
    }
    public Integer update(Admin admin){
        AdminExample adminExample = new AdminExample();  //example 示例查询，给我一个例子 我按例子查询
        adminExample.createCriteria().andAdidEqualTo(admin.getAdid()); //createCriteria() 创建一个criteria接口的匿名实现类，添加一个where子句 and表达式 这次and的是adid=admin对象的adid
        return adminMapper.updateByExampleSelective(admin,adminExample);
    }
}
